package org.kolonitsky.css;

import org.w3c.css.sac.CSSException;
import org.w3c.css.sac.CSSParseException;
import org.w3c.css.sac.ErrorHandler;

/**
 * @author Alex.Kolonitsky
 */
public class MyCssErrorHandler implements ErrorHandler {

    public static final ErrorHandler INSTANCE = new MyCssErrorHandler();

    public static final String MESSAGE_FORMAT = "%s: %4d:%4d - %s";

    public void warning(CSSParseException e) throws CSSException {
        log("Warning", e);
    }

    public void error(CSSParseException e) throws CSSException {
        log("Error  ", e);
    }

    public void fatalError(CSSParseException e) throws CSSException {
        log("Fatal  ", e);
    }

    protected void log(String severity, CSSParseException e) {
        System.out.println(String.format(MESSAGE_FORMAT, severity, e.getLineNumber(), e.getColumnNumber(), e.getMessage()));
    }
}
